home *** CD-ROM | disk | FTP | other *** search
/ El Mac 9 / El Mac 9.iso / Shareware / Applications / MathPad 2.4 / XFuns / XFun kit / slider src / slevent.c next >
Encoding:
C/C++ Source or Header  |  1996-03-27  |  3.6 KB  |  157 lines  |  [TEXT/CWIE]

  1. #include "callbackg.h"
  2. #include "sliders.h"
  3. #include "xfuns.h"
  4.  
  5. extern  ControlActionUPP scroller;
  6.  
  7. static int busy = FALSE;
  8.  
  9. static void ReEval(void)    // force MathPad to re-evaluate its current document
  10. {
  11.    GrafPtr wind;
  12.    
  13.    GetPort(&wind);
  14.    DoMenuItem((131L<<16) | 13);    // menuid=131 (MathPad)   item=13 (Reevaluate)
  15.    SetPort(wind);
  16. }
  17.  
  18. pascal void ScrollProc(ControlHandle theControl,short part)
  19. {
  20.    int bump;
  21.  
  22.    switch (part)
  23.    {
  24.     case inThumb:      bump =  0; break;
  25.     case inUpButton:   bump = -1; break;
  26.     case inDownButton: bump =  1; break;
  27.     case inPageUp:     bump =-10; break;
  28.     case inPageDown:   bump = 10; break;
  29.     default: return;
  30.    }
  31.    
  32.    if(!busy)    // parser is not reentrant! Don't force ReEval if it hasn't finished last eval.
  33.    {
  34.     SetCtlValue(theControl,GetCtlValue(theControl)+bump);
  35.     ReEval();
  36.    }
  37. }
  38.  
  39. static int DoControl(WindowPtr theWindow,Point where)
  40. {
  41.    int part;
  42.    ControlHandle theControl;
  43.    GlobalToLocal(&where);
  44.    part = FindControl(where,theWindow,&theControl);
  45.    if(!part) return(FALSE);    /* mousedown was not in a control */
  46.  
  47.    if(part == inThumb)    /* Note: only kind of control is scrollbar */
  48.    {
  49.     TrackControl(theControl,where,0L);
  50.     if(!busy) ReEval();
  51.    }
  52.    else
  53.     TrackControl(theControl,where,scroller);    /* 68K could just use &ScrollProc. PPC can't*/
  54.    return(TRUE);   
  55. }
  56.  
  57. static int DoMouseDown(EventRecord    *theEvent)
  58. {
  59.     WindowPtr theWindow;
  60.     int    partCode;
  61.     Rect sizeLimit;
  62.     GrafPtr oldPort;
  63.  
  64.     partCode = FindWindow(theEvent->where,&theWindow);
  65.     
  66.     if(partCode == inMenuBar) return(FALSE);
  67.      if(!IsSlider(theWindow)) return(FALSE);
  68.      
  69.     switch(partCode)
  70.     {
  71.       case inDrag:
  72.         SetRect(&sizeLimit,0,25,4000,4000);
  73.         SelectWindow(theWindow);
  74.           DragWindow(theWindow,theEvent->where,&sizeLimit);
  75.         break;
  76.             
  77.       case inContent:
  78.         /*
  79.         pseudo floating window trick. Don't select the window, but do
  80.         the control anyway. This makes all slider controls active as if
  81.         they were in front even if the window manager doesn't know it.
  82.         */
  83.         GetPort(&oldPort);
  84.         SetPort(theWindow);
  85.         DoControl(theWindow,theEvent->where);
  86.         SetPort(oldPort);
  87.         break;
  88.           
  89.       case inGoAway:
  90.           if(TrackGoAway(theWindow,theEvent->where))
  91.           {
  92.            if(theEvent->modifiers & optionKey) KillAllSliders();
  93.            else KillSlider(theWindow);
  94.         }
  95.         break;
  96.      }
  97.      return(TRUE);
  98. }
  99.  
  100. static void Update(WindowPtr theWindow)
  101. {
  102.     GrafPtr oldPort;
  103.     GetPort(&oldPort);
  104.     SetPort(theWindow);
  105.     BeginUpdate(theWindow);
  106.     UpdtControl(theWindow,theWindow->visRgn);
  107.     EndUpdate(theWindow);
  108.     SetPort(oldPort);
  109. }
  110.  
  111. short doevent(EventRecord *theEvent)
  112. {
  113.     switch (theEvent->what)
  114.     {
  115.      case mouseDown:
  116.       return DoMouseDown(theEvent);
  117.       
  118.      case updateEvt:
  119.       if(IsSlider((WindowPtr)(theEvent->message)))
  120.       {
  121.        Update((WindowPtr)(theEvent->message));
  122.        return(TRUE);
  123.       }
  124.       break;
  125.       
  126.      case activateEvt:    // required event but no action needed
  127.       return(IsSlider((WindowPtr)(theEvent->message)));
  128.  
  129.      case app3Evt:        // message from MathPad
  130.       if(theEvent->message == BEGINPARSE) busy = TRUE;
  131.       else if(theEvent->message == ENDPARSE) busy = FALSE;
  132.       break;
  133.      
  134.      case app4Evt:
  135.       if((theEvent->message & 0xFF000000) == 0x01000000)
  136.       {
  137.           if(theEvent->message & 1)    /* resume */
  138.            activate();
  139.           else                         /* suspend */
  140.            deactivate();
  141.          return(FALSE);    // MathPad needs to do further processing on this event
  142.       }
  143.       else
  144.           if((theEvent->message & 0xFF000000) == 0xFA000000)    // mouse moved
  145.           {
  146.            if(IsSlider(FrontWindow()))    // front window is required to handle mouse moved
  147.            {
  148.            SetCursorRegion(NULL,NULL);    // just use arrow cursor
  149.            return(TRUE);
  150.           }
  151.          }
  152.       break;
  153.     }
  154.     return(FALSE);
  155. }
  156.  
  157.